package com.example.springbootlearning.handler;

import com.example.springbootlearning.base.BizException;
import com.example.springbootlearning.base.ExceptionEnum;
import com.example.springbootlearning.base.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

/**
 * ClassName: GlobalExceptionHandler
 * Package: com.example.springbootlearning.handler
 * Package: com.example.springbootlearning.handler
 * Desription:
 *
 * @Author: happen
 * @CreateTime: 2024/6/5 15:53
 * @Version: V1.0
 */
@ControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler({Exception.class})
    public String exceptionHandler(Exception e) {
        System.out.println("全局异常捕获>>>:"+e);
        return "全局异常捕获,错误原因>>>"+e.getMessage();
    }

    @ExceptionHandler({BizException.class})
    public Result bizExceptionHandler(BizException e) {
        return Result.error(Integer.parseInt(ExceptionEnum.SERVER_BUSY.getResultCode()),ExceptionEnum.SERVER_BUSY.getResultMsg());
    }
}
